package com.openbravo.pos.payment;

import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppProperties;
import com.openbravo.pos.util.AltEncrypter;
import com.sun.net.ssl.internal.ssl.Provider;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URLDecoder;
import java.net.UnknownHostException;
import java.rmi.RemoteException;
import java.security.Security;
import java.util.Currency;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class PaymentGatewayPayPoint
  implements PaymentGateway
{
  private static final String ENDPOINTADDRESS = "https://www.secpay.com/java-bin/soap";
  private static final QName OPERATIONVALIDATE = new QName("SECCardService", "validateCardFull");
  private static final QName OPERATIONREFUND = new QName("SECCardService", "refundCardFull");
  private String m_sCommerceID;
  private String m_sCommercePassword;
  private String m_sCurrency;
  private boolean m_bTestMode;

  public PaymentGatewayPayPoint(AppProperties paramAppProperties)
  {
    System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
    Security.addProvider(new Provider());
    this.m_sCommerceID = paramAppProperties.getProperty("payment.commerceid");
    AltEncrypter localAltEncrypter = new AltEncrypter(new StringBuilder().append("cypherkey").append(paramAppProperties.getProperty("payment.commerceid")).toString());
    this.m_sCommercePassword = localAltEncrypter.decrypt(paramAppProperties.getProperty("payment.commercepassword").substring(6));
    this.m_bTestMode = Boolean.valueOf(paramAppProperties.getProperty("payment.testmode")).booleanValue();
    this.m_sCurrency = (Locale.getDefault().getCountry().isEmpty() ? Currency.getInstance("EUR").getCurrencyCode() : Currency.getInstance(Locale.getDefault()).getCurrencyCode());
  }

  public PaymentGatewayPayPoint()
  {
  }

  public void execute(PaymentInfoMagcard paramPaymentInfoMagcard)
  {
    try
    {
      Service localService = new Service();
      Call localCall = (Call)localService.createCall();
      localCall.setTargetEndpointAddress("https://www.secpay.com/java-bin/soap");
      Object[] arrayOfObject;
      if (paramPaymentInfoMagcard.getTotal() > 0.0D)
      {
        localCall.setOperationName(OPERATIONVALIDATE);
        arrayOfObject = new Object[] { this.m_sCommerceID, this.m_sCommercePassword, paramPaymentInfoMagcard.getTransactionID(), InetAddress.getLocalHost().getHostAddress(), paramPaymentInfoMagcard.getHolderName(), paramPaymentInfoMagcard.getCardNumber(), Double.toString(paramPaymentInfoMagcard.getTotal()), paramPaymentInfoMagcard.getExpirationDate(), "", "", "", "", "", new StringBuilder().append(this.m_bTestMode ? "test_status=true," : "test_status=live,").append("dups=false,currency=").append(this.m_sCurrency).toString() };
      }
      else
      {
        localCall.setOperationName(OPERATIONREFUND);
        arrayOfObject = new Object[] { this.m_sCommerceID, this.m_sCommercePassword, paramPaymentInfoMagcard.getTransactionID(), Double.toString(Math.abs(paramPaymentInfoMagcard.getTotal())), "secpay", new StringBuilder().append("refund").append(paramPaymentInfoMagcard.getTransactionID()).toString() };
      }
      String str1 = (String)localCall.invoke(arrayOfObject);
      paramPaymentInfoMagcard.setReturnMessage(str1);
      if (str1 == null)
      {
        paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Response empty.");
      }
      else
      {
        HashMap localHashMap = new HashMap();
        StringTokenizer localStringTokenizer = new StringTokenizer(str1, "?&");
        String str2;
        while (localStringTokenizer.hasMoreTokens())
        {
          str2 = localStringTokenizer.nextToken();
          int i = str2.indexOf(61);
          if (i >= 0)
            localHashMap.put(URLDecoder.decode(str2.substring(0, i), "UTF-8"), URLDecoder.decode(str2.substring(i + 1), "UTF-8"));
          else
            localHashMap.put(URLDecoder.decode(str2, "UTF-8"), null);
        }
        if ("true".equals(localHashMap.get("valid")))
        {
          paramPaymentInfoMagcard.paymentOK((String)localHashMap.get("auth_code"), (String)localHashMap.get("trans_id"), str1);
        }
        else
        {
          str2 = (String)localHashMap.get("code");
          if ("N".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymentnotauthorised"), (String)localHashMap.get("message"));
          else if ("C".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Communication problem. Trying again later may well work.");
          else if ("P:A".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Amount not supplied or invalid.");
          else if ("P:X".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Not all mandatory parameters supplied.");
          else if ("P:P".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Same payment presented twice.");
          else if ("P:S".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Start date invalid.");
          else if ("P:E".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Expiry date invalid.");
          else if ("P:I".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Issue number invalid.");
          else if ("P:C".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Card number fails LUHN check.");
          else if ("P:T".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Card type invalid - i.e. does not match card number prefix.");
          else if ("P:N".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Customer name not supplied.");
          else if ("P:M".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Merchant does not exist or not registered yet.");
          else if ("P:B".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Merchant account for card type does not exist.");
          else if ("P:D".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Merchant account for this currency does not exist.");
          else if ("P:V".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "CVV2 security code mandatory and not supplied / invalid.");
          else if ("P:R".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "Transaction timed out awaiting a virtual circuit. Merchant may not have enough virtual circuits for the volume of business.");
          else if ("P:#".equals(str2))
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterror"), "No MD5 hash / token key set up against account.");
          else
            paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymenterrorunknown"), "");
        }
      }
    }
    catch (UnknownHostException localUnknownHostException)
    {
      paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymentexceptionservice"), localUnknownHostException.getMessage());
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymentexceptionservice"), localUnsupportedEncodingException.getMessage());
    }
    catch (ServiceException localServiceException)
    {
      paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymentexceptionservice"), localServiceException.getMessage());
    }
    catch (RemoteException localRemoteException)
    {
      paramPaymentInfoMagcard.paymentError(AppLocal.getIntString("message.paymentexceptionremote"), localRemoteException.getMessage());
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.PaymentGatewayPayPoint
 * JD-Core Version:    0.6.0
 */